<?php
$http = new \Swoole\Http\Server('0.0.0.0',6060);
//配置
$http->set([
//    'daemonize'=>1,//守护进程
    'worker_num'=>1,
    //静态资源配置选项
    //虚拟目录指向的位置，只针对静态文件 html js img video
    'document_root'=>'/wwwdata/web',
    'enable_static_handler'=>'true',
]);
//事件
$http->on("request",function ($request,$response) {
    $req_file = $request->server['request_uri'];
    $filepath = __DIR__ . "/web/" . $req_file;
    //状态码
    $status = 404;
    //JSON_UNESCAPED_UNICODE php5.4以上提供，解决中文乱码问题 256
    $html = json_encode(['status'=>'404','msg'=>'页面跑丢了'],JSON_UNESCAPED_UNICODE);
    //判断文件是否存在
    if (file_exists($filepath))
    {
        $_GET = $request->get;
        $_POST = $request->post;
        $_FILES = $request->files;

        //文件一定存在
        //状态码
        $status = 200;
        //开启缓冲区
        ob_start();
        include $filepath;
        //读取缓冲区数据
        $html = ob_get_contents();
        //清空缓冲区
        ob_clean();

    }
//    var_dump($req_file);
    $response->status($status);
    $response->header("Content-Type", "application/json; charset=utf-8");
    $response->end($html);
//    $response->end("<h1 style='margin: auto'>冯媛：你哥说你特傻！！！</h1><br><img src='https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1406166804,3744562059&fm=15&gp=0.jpg'>");
//        $response->end("<h1 style='margin: auto'>冯媛：你哥说你像下边的小可爱！！！</h1><br><img src='https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3090162626,3597556694&fm=26&gp=0.jpg'>");

});

$http->start();